//
//  LoginService.m
//  WisdomStar
//
//  Created by 谭飞 on 2018/11/2.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "LoginService.h"
#import "LoginAPI.h"

@implementation LoginService

/**
 用户登录

 @param account 账号
 @param password 密码
 */
+ (void)loginWithAccout:(NSString *)account password:(NSString *)password complete:(nonnull void (^)(BOOL))completion {
    LoginAPI *api = [[LoginAPI alloc] init];
    NSMutableDictionary *mdic = [NSMutableDictionary dictionary];
    mdic[@"mobile"] = account;
    mdic[@"password"] = password;
    api.outerParameters = mdic;
    [SVProgressHUD show];
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        ResponseModel *resModel = [ResponseModel yy_modelWithJSON:request.responseObject];
        [TFUserDefault setValue:resModel.data[@"token"] forKey:@"token"];
        [TFUserDefault setValue:resModel.data[@"is_teacher"] forKey:@"identity"];
        [DATAMODEL.configDBHelper updateToken:resModel.data[@"token"]];
        [TFUserDefault setValue:resModel.data[@"r_token"] forKey:@"RCToken"];
        completion(true);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        IOAResponse *response = [IOAResponse responseWithRequest:request];
        [SVProgressHUD showError:response.responseMessage];
        completion(false);
    }];
}

@end
